package com.itheima.controller.admin;

import com.itheima.DTO.YddCateDTO;
import com.itheima.DTO.YddCatePageDTO;
import com.itheima.VO.YddCateVO;
import com.itheima.entity.YddCate;
import com.itheima.json.PageBean;
import com.itheima.result.Result;
import com.itheima.service.YddCateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ydd_cate")
@RequiredArgsConstructor
@Slf4j
public class YddCateController {

    private final YddCateService yddCateService;

    @GetMapping("/all")
    public Result<?> all() {
        List<YddCate> yddCateList = yddCateService.selectAllCate();
        return Result.success(yddCateList);
    }

    @GetMapping("/list")
    public Result<?> list(YddCatePageDTO yddCatePageDTO){
        PageBean<YddCateVO> catePageBean = yddCateService.page(yddCatePageDTO);
        return Result.success(catePageBean);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody YddCateDTO yddCateDTO){
        yddCateService.addYddCate(yddCateDTO);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<?> rowInfo(Integer id){
        YddCateVO yddCateVO = yddCateService.selectCateInfoById(id);
        return Result.success(yddCateVO);
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody YddCateDTO yddCateDTO){
        yddCateService.update(yddCateDTO);
        return Result.success();
    }

    @GetMapping("/del")
    public Result<?> delete(Integer id){
        yddCateService.deleteCateById(id);
        return Result.success();
    }
}
